import os, sys
import pprint

from dbmanager import DBManager

dbm = DBManager ( DBManager.DBM_TYPE_MYSQL )
dbm.connect ( host = "10.0.20.155", user = "test", passwd = "test", db = "test" )
dbm.debug = sys.stderr.write

dbm.table_add ( "table1",
	# fields
	(
		{
			"name": "id",
			"type": "INT UNSIGNED",
			"nullable": False,
			"extra": "AUTO_INCREMENT"
		},
		{
			"name": "name",
			"type": "VARCHAR(250)"
		},
		{
			"name": "surname",
			"type": "VARCHAR(250)"
		},
		{
			"name": "cfisc",
			"type": "VARCHAR(251)"
		},
		{
			"name": "enabled",
			"type": "BOOLEAN"
		}
		
	),
	# indexes
	(
		{
			"type": "PRIMARY KEY",
			"columns": ["id"],
		},
		{
			"type": "UNIQUE",
			"columns": ["name", "surname"],
		},
		{
			"type": "INDEX",
			"columns": ["cfisc"],
		}
	)
)


dbm.view_add ( "view1",	{
				"tables": ["table1"],
				"sql": "select * from table1"
			} )

#dbm.table_drop ( "table1" )
#dbm.table_create ( "table1" )

#pprint.pprint ( dbm.table_compare ( "table1" ) )
#dbm.table_apply ( "table1" )
#pprint.pprint ( dbm.table_compare ( "table1" ) )

#dbm.view_create ( "view1" )

print "PRIMA"
pprint.pprint ( dbm.db_compare () )

dbm.db_apply ()

print "DOPO"
pprint.pprint ( dbm.db_compare () )



